# -*- coding: utf-8 -*-
# @Date    : 2015-06-21 15:50:35
# @Author  : Your Name (you@example.org)
# @Link    : http://example.org
# @Version : $Id$

from lib.tornado_routes import route
from web.handler import BaseHandler
from tornado import gen
from tornado.web import asynchronous

from web.models.admin.thumb.thumb import Thumb
from lib.libpage import start as pagestart

@route(r'/admin/thumb/rank/month/?')
class IndexHandler(BaseHandler):
    @asynchronous
    @gen.coroutine
    def get(self):
        model = Thumb()
        rest = yield model.listmonth()
        
        ret=rest['ret']
        nmonth=rest['nmonth']
      

        self.render("admin/thumb/month.html",ret=ret,nmonth=nmonth)

#搜索
@route(r'/admin/thumb/rank/monthsr/?')
class IndexsrHandler(BaseHandler):
    @asynchronous
    @gen.coroutine
    def post(self):
        model=Thumb()
        Fcreate_time=self.get_argument('Fcreate_time',default='2015-01')
        Ftype_id=self.get_argument('Ftype_id',default=1)
        rest = yield model.monthsr(Fcreate_time,Ftype_id)
        ret=rest['ret']
        if Fcreate_time:
            nmonth=Fcreate_time
        else:
            nmonth=rest['nmonth']
        self.render("admin/thumb/month.html",ret=ret,nmonth=nmonth)

@route(r'/admin/thumb/rank/year/?')
class IndexyearHandler(BaseHandler):
    @asynchronous
    @gen.coroutine
    def get(self):
        model = Thumb()
        rest = yield model.listyear()
        
        ret=rest['ret']
        nyear=rest['nyear']
        self.render("admin/thumb/year.html",ret=ret,nyear=nyear)


#搜索
@route(r'/admin/thumb/rank/yearsr/?')
class IndexyearsrHandler(BaseHandler):
    @asynchronous
    @gen.coroutine
    def post(self):
        model=Thumb()
        Fcreate_time=self.get_argument('Fcreate_time',default='2015-01')
        Ftype_id=self.get_argument('Ftype_id',default=1)
        rest = yield model.yearsr(Fcreate_time,Ftype_id)
        ret=rest['ret']
        if Fcreate_time:
            nyear=Fcreate_time
        else:
            nyear=rest['nyear']
        self.render("admin/thumb/year.html",ret=ret,nyear=nyear)